﻿///***************************************************************
/// 시  스  템 : Updms.Fit
/// 단위시스템 : FIT
/// 계      층 : Presentation Layer
/// 프로그램명 : Fit2010r
/// 파  일  명 : Fit2010r.aspx.cs
/// 설      명 : 트레이닝분석표
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2015-01-19 송시명   최초 작성
///***************************************************************
using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using SMFramework.Data;
using SMFramework.Utility;
using SMFramework.Web.UI.WebControls.SMGridView;

using Base.AppFramework.Web.UI.CommandBar;
using Base.Dac;

using Updms.Common.BaseClass;

using Updms.Com.Exe;
using Updms.Fit.Exe;

namespace Updms.Fit
{
	public partial class Fit2010r : Updms.Common.BaseClass.PageBase
	{
		#region 전역영역

		public static readonly string PID = "Fit2010r";
		public static readonly string gs_path_info = "/updms/Fit/" + PID + ".aspx";

		Global global = new Global();
		CommCode.Com com = new CommCode.Com(LANG_SET);
		CommCode.Fit fit = new CommCode.Fit(LANG_SET);

		//검색
		protected string kw1 = "";	//검색기간-시작
		protected string kw2 = "";	//검색기간-종료
		protected string kw3 = "";	//운동부위
		protected string kw4 = "";	//운동명
		protected string kw5 = "";	//조회타입

		//메뉴 선택값
		protected string gs_sm = "";

		#endregion

		#region Page_Load, OnPageLoad

		protected void Page_Load(object sender, EventArgs e)
		{
			SetInit();
			if (!Page.IsPostBack)
			{
				// 최초 화면 로딩시 처리해야 할 부분
				OnPageLoad();
				SearchProcess();
			}
			else
			{
				CallJavaScriptMethodInAjax("setResize();");
			}
			SetClientScriptNoPostBack();
		}

		// OnPageLoad
		private void OnPageLoad()
		{
			SetLiterals(global.GetLabelInfoByPgmId(PID, LANG_SET));
			SetClientScript();
			SetYearMonth();
			SetSearchTrainingPart();
			SetSearchTrainingType();
			SetSearchDiv();
			SetSearchParameter();
		}

		#endregion

		#region InitializeComponent

		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);
			this.PreRender += new System.EventHandler(this.Page_PreRender);
		}

		#endregion

		#region SetClientScript, SetClientScriptNoPostBack

		private void SetClientScript()
		{
		}

		//포스트백과 무관하게 이벤트 지정
		private void SetClientScriptNoPostBack()
		{
			cbl_search_training_part.Items[0].Attributes.Add("onclick", "checkBoxListCheck('cbl_search_training_part');");
			cbl_search_training_type.Items[0].Attributes.Add("onclick", "checkBoxListCheck('cbl_search_training_type');");
		}

		#endregion

		#region SetInit, SetSearchParameter

		//초기값설정
		private void SetInit()
		{
			lbl_search_flag.Text = "INIT";
			gs_sm = (Request.QueryString["sm"] == null || Request.QueryString["sm"].Trim().Length != 7)
					? global.GetDirDepth(PID) : Request.QueryString["sm"].ToString();
		}

		//검색파라미터
		private void SetSearchParameter()
		{
			switch (lbl_search_flag.Text.Trim().ToUpper())
			{
				case "INIT":
					if (String.IsNullOrEmpty(Request.QueryString["kw1"]))
					{
						kw1 = ddl_search_from_year.SelectedValue + "-" + ddl_search_from_month.SelectedValue;
					}
					else
					{
						kw1 = Server.UrlDecode(Request.QueryString["kw1"]);
						ddl_search_from_year.SelectedValue = kw1.Substring(0, 4);
						ddl_search_from_month.SelectedValue = kw1.Substring(5, 2);
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw2"]))
					{
						kw2 = ddl_search_to_year.SelectedValue + "-" + ddl_search_to_month.SelectedValue;
					}
					else
					{
						kw2 = Server.UrlDecode(Request.QueryString["kw2"]);
						ddl_search_to_year.SelectedValue = kw2.Substring(0, 4);
						ddl_search_to_month.SelectedValue = kw2.Substring(5, 2);
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw3"]))
					{
						kw3 = WebControlUtil.GetCheckBoxListValue(cbl_search_training_part, 1);
					}
					else
					{
						kw3 = Server.UrlDecode(Request.QueryString["kw3"]);
						WebControlUtil.SetCheckBoxListValue(cbl_search_training_part, kw3);
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw4"]))
					{
						kw4 = WebControlUtil.GetCheckBoxListValue(cbl_search_training_type, 1);
					}
					else
					{
						kw4 = Server.UrlDecode(Request.QueryString["kw4"]);
						WebControlUtil.SetCheckBoxListValue(cbl_search_training_type, kw4);
					}

					if (String.IsNullOrEmpty(Request.QueryString["kw5"]))
					{
						kw5 = rbl_search_type.SelectedValue;
					}
					else
					{
						kw5 = Server.UrlDecode(Request.QueryString["kw5"]);
						rbl_search_type.SelectedValue = kw5;
					}

					break;
				case "SEARCH":
					kw1 = ddl_search_from_year.SelectedValue + "-" + ddl_search_from_month.SelectedValue;
					kw2 = ddl_search_to_year.SelectedValue + "-" + ddl_search_to_month.SelectedValue;
					kw3 = WebControlUtil.GetCheckBoxListValue(cbl_search_training_part, 1);
					kw4 = WebControlUtil.GetCheckBoxListValue(cbl_search_training_type, 1);
					kw5 = rbl_search_type.SelectedValue;
					break;
			}
		}

		#endregion

		#region 마스터 Method (SetYearMonth, SetSearchTrainingPart, SetSearchTrainingType, SetSearchDiv)

		//기준년도 설정
		private void SetYearMonth()
		{
			ddl_search_from_year.Items.Clear();
			ddl_search_to_year.Items.Clear();

			//2014년부터 현재년
			int li_t_year = Convert.ToInt32(DateUtil.GetYearEx(0, "yyyy"));
			for (int i = 2014; i <= li_t_year; i++)
			{
				string ls_year = i.ToString();
				ddl_search_from_year.Items.Add(new ListItem(ls_year, ls_year));
				ddl_search_to_year.Items.Add(new ListItem(ls_year, ls_year));
			}

			SetYearMonth(-11);
		}

		// 검색조건의 년월설정 - 기간지정
		private void SetYearMonth(int li_term)
		{
			ddl_search_from_year.SelectedValue = DateUtil.GetMonthEx(li_term, "yyyy"); //x개월전년도
			ddl_search_from_month.SelectedValue = DateUtil.GetMonthEx(li_term, "MM"); //x개월전월
			ddl_search_to_year.SelectedValue = DateUtil.GetYearEx(0, "yyyy"); // 현재년도
			ddl_search_to_month.SelectedValue = DateUtil.GetMonthEx(0, "MM"); // 현재월
		}

		//운동부위
		private void SetSearchTrainingPart()
		{
			fit.SetTrainingPart(cbl_search_training_part);

			cbl_search_training_part.Items.Insert(0, new ListItem(GetXmlMsg("STR_019"), "ALL"));	//전체선택

			if (cbl_search_training_part.Items.Count > 0)
			{
				for (int i = 0; i < cbl_search_training_part.Items.Count; i++)
				{
					cbl_search_training_part.Items[i].Selected = true;
				}
			}
		}

		//운동명
		private void SetSearchTrainingType()
		{
			DataSet lo_ds = new DataSet();
			Fit1010m_NT _Fit1010m_NT = new Fit1010m_NT();

			lo_ds.Merge(_Fit1010m_NT.GetTrainingType());

			cbl_search_training_type.Items.Clear();
			cbl_search_training_type.DataSource = lo_ds;
			cbl_search_training_type.DataMember = "UPDMS_FIT_TRAINING_TYPE";
			cbl_search_training_type.DataTextField = "Training_Nm";
			cbl_search_training_type.DataValueField = "Training_Type_Id";
			cbl_search_training_type.DataBind();

			cbl_search_training_type.Items.Insert(0, new ListItem(GetXmlMsg("STR_019"), "ALL"));	//전체선택
		}

		//조회타입
		private void SetSearchDiv()
		{
			fit.SetSearchDiv(rbl_search_type);
		}

		#endregion

		#region 마스터 (SetPrevNextYear, SetThisYear, SetEnabledYearBtn)

		//전년, 차년버튼 누르면
		private void SetPrevNextYear(int pi_year_cnt)
		{
			string ls_year = ddl_search_to_year.SelectedValue;
			string ls_calc_year = Convert.ToString(Convert.ToInt32(ls_year) + pi_year_cnt);

			if (WebControlUtil.CheckDdlValue(ddl_search_from_year, ls_calc_year))
			{
				ddl_search_from_year.SelectedValue = ls_calc_year;
			}
			if (WebControlUtil.CheckDdlValue(ddl_search_to_year, ls_calc_year))
			{
				ddl_search_to_year.SelectedValue = ls_calc_year;
			}

			//월 처리
			ddl_search_from_month.SelectedIndex = 0; //1월
			ddl_search_to_month.SelectedIndex = ddl_search_to_month.Items.Count - 1; //12월

			//버튼처리
			SetEnabledYearBtn();
		}

		//당년설정
		private void SetThisYear()
		{
			string ls_this_year = DateUtil.GetNow("yyyy");
			ddl_search_from_year.SelectedValue = ls_this_year;
			ddl_search_to_year.SelectedValue = ls_this_year;

			//월 처리
			ddl_search_from_month.SelectedIndex = 0; //1월
			ddl_search_to_month.SelectedIndex = ddl_search_to_month.Items.Count - 1; //12월

			SetEnabledYearBtn();
		}

		//전년, 차년버튼 처리
		private void SetEnabledYearBtn()
		{
			ibtn_prev_year.Enabled = (ddl_search_from_year.SelectedIndex == 0) ? false : true;
			ibtn_next_year.Enabled = (ddl_search_to_year.SelectedIndex == ddl_search_to_year.Items.Count - 1) ? false : true;
		}

		#endregion

		#region 디테일 Method (SetChartTotalWeightCountByTrainingPart, SetChartMonthlyTotalWeightTrainingAnalysis, SetChartTrainingPart, SetChartTrainingType)

		#region 운동부위별 총량 챠트
		//운동부위별 총량 챠트
		private void SetChartTotalWeightCountByTrainingPart(DataSet lo_ds, string dt_name)
		{
			//초기화
			chart_total_weight_count_by_training_part.Data.Clear();
			chart_total_weight_count_by_training_part.Series.Clear();

			int li_count = DataSetUtil.GetRowCount(lo_ds, dt_name);

			ltr_total_weight_or_count_pie.Text = " (" + rbl_search_type.SelectedItem.Text + ")";

			for (int i = 0; i < li_count; i++)
			{
				string trainingTypeId = DataSetUtil.GetFldStr(lo_ds, dt_name, i, "Training_Type_Id");

				//소계만
				if (trainingTypeId == "BA001")
				{
					string ls_label = DataSetUtil.GetFldStr(lo_ds, dt_name, i, "Training_Part_Nm");
					double ld_total = DataSetUtil.GetFldDbl(lo_ds, dt_name, i, "Total");

					chart_total_weight_count_by_training_part.Data[0, i] = ld_total;
					chart_total_weight_count_by_training_part.AxisX.Labels[i] = ls_label;

					//운동부위 체크박스리스트 바인딩
					string ls_training_part = DataSetUtil.GetFldStr(lo_ds, dt_name, i, "Training_Part");
					for (int j = 0; j < cbl_search_training_part.Items.Count; j++)
					{
						if (cbl_search_training_part.Items[j].Value == ls_training_part && !cbl_search_training_part.Items[j].Selected)
						{
							cbl_search_training_part.Items[j].Selected = true;
						}
					}
				}
			}
		}
		#endregion

		#region 월별트레이닝결과 챠트
		//월별트레이닝결과 챠트
		private void SetChartMonthlyTotalWeightTrainingAnalysis(DataSet lo_ds, string dt_name)
		{
			SetSearchParameter();

			ltr_total_weight_or_count_line.Text = " (" + rbl_search_type.SelectedItem.Text + ")";

			//초기화
			chart_training_type.Data.Clear();
			chart_training_type.Series.Clear();

			string[] columns = DateUtil.GetDiffMonthList(kw1, kw2).Split(','); //검색기간 차이로 gv에서 조회할 데이터의 column index를 구한다

			DataTable dt = new DataTable();
			dt.Columns.Add("Training_Part_Nm");

			for (int i = 0; i < columns.Length; i++)
			{
				dt.Columns.Add(columns[i]); //2014-01,...
			}

			DataRow dr;

			if (DataSetUtil.CheckRowCount(lo_ds, dt_name))
			{
				//시리즈
				chart_training_type.Data.Series = WebControlUtil.GetCheckedItemsCount(cbl_search_training_part);

				//데이터셋에서 소계데이터만 추출
				DataRow[] drColumns = lo_ds.Tables[dt_name].Select("Training_Type_Id = 'BA001'");
				foreach (DataRow drTemp in drColumns)
				{
					dr = dt.NewRow();
					dr["Training_Part_Nm"] = drTemp["Training_Part_Nm"].ToString();

					for (int j = 0; j < columns.Length; j++)
					{
						dr[columns[j]] = drTemp[columns[j]];
					}

					dt.Rows.Add(dr);
					dt.AcceptChanges();
				}

				for (int k = 0; k < dt.Rows.Count; k++)
				{
					//운동부위는 제외
					for (int l = 1; l < dt.Columns.Count; l++)
					{
						//수동으로 데이터 바인딩
						chart_training_type.Data[k, l - 1] = Convert.ToDouble(dt.Rows[k][l].ToString());

						//X축 라벨링
						chart_training_type.AxisX.Labels[l - 1] = "'" + columns[l - 1].Substring(2, 5).Replace("-", "."); //2014-12 -> '14.12

						//0은 안보여준다
						chart_training_type.Points[k, l - 1].PointLabels.Visible = (chart_training_type.Data[k, l - 1] > 0);
					}

					chart_training_type.Series[k].Text = dt.Rows[k]["Training_Part_Nm"].ToString();
					chart_training_type.Series[k].MarkerShape = ChartFxUtil.markerShape(k);
				}

				dt.Clear();
			}
		}

		#endregion

		#region 운동부위별 챠트 (ModalPopup)
		//운동부위별 챠트
		private void SetChartTrainingPart(GridView gv, int first_month_idx, string training_part, bool isByWeight)
		{
			SetSearchParameter();
			chart_line_part.MainPane.AxisY.Title.Text = isByWeight ? "중량 (㎏)" : "횟수";

			//초기화
			chart_line_part.Data.Clear();
			chart_line_part.Series.Clear();

			string[] columns = DateUtil.GetDiffMonthList(kw1, kw2).Split(','); //검색기간 차이로 gv에서 조회할 데이터의 column index를 구한다

			//운동부위별 운동수
			for (int i = 0; i < gv.Rows.Count; i++)
			{
				string gvTrainingPart = gv.DataKeys[i].Values["Training_Part"].ToString();
				string gvTrainingTypeId = gv.DataKeys[i].Values["Training_Type_Id"].ToString();

				if ((training_part == gvTrainingPart) && (gvTrainingTypeId != "BA001"))
				{
					for (int j = 0; j < columns.Length; j++)
					{
						double value = Convert.ToDouble(ConversionUtil.RemoveComma(ConversionUtil.ExtractStrBtwnChar(gv.Rows[i].Cells[j + first_month_idx].Text, ");\">", "</span>")));

						//수동으로 데이터 바인딩
						chart_line_part.Data[i, j] = value;

						//X축 라벨링 2014-12 -> 14-12 -> '14.12
						string gvHeaderText = gv.HeaderRow.Cells[j + first_month_idx].Text;
						string ls_base_dt = "'" + gvHeaderText.Substring(2, 5).Replace("-", ".");
						chart_line_part.AxisX.Labels[j] = ls_base_dt;

						//0이상일때만 보여준다.
						if (chart_line_part.Data[i, j] > 0)
						{
							chart_line_part.Points[i, j].PointLabels.Visible = true;
						}
						else
						{
							chart_line_part.Points[i, j].PointLabels.Visible = false;
						}
					}

					//시리즈
					chart_line_part.Series[i].Text = ConversionUtil.ExtractStrBtwnChar(gv.Rows[i].Cells[3].Text, "');\">", "</a>");
				}
			}

			mpe_chart_part.Show();
		}
		#endregion

		#region 운동별 챠트 (ModalPopup)
		//운동별 챠트
		private void SetChartTrainingType(GridView gv, int first_month_idx, int row_idx, bool isByWeight)
		{
			SetSearchParameter();

			//시리즈
			chart_line_type.Data.Series = 1;
			chart_line_type.Series[0].Text = h_row_series_type.Value;

			chart_line_type.MainPane.AxisY.Title.Text = isByWeight ? "중량 (㎏)" : "횟수";

			//초기화
			chart_line_type.Data.Clear();

			string[] columns = DateUtil.GetDiffMonthList(kw1, kw2).Split(','); //검색기간 차이로 gv에서 조회할 데이터의 column index를 구한다
			double ld_avg = 0.0; //평균
			double ld_sum = 0; //합계
			int li_cnt = 0; //0이상인 월의 수

			for (int i = 0; i < columns.Length; i++)
			{
				double value = Convert.ToDouble(ConversionUtil.RemoveComma(ConversionUtil.ExtractStrBtwnChar(gv.Rows[row_idx].Cells[i + first_month_idx].Text, ");\">", "</span>")));
				ld_sum = ld_sum + value;

				//수동으로 데이터 바인딩
				chart_line_type.Data[0, i] = value;

				//X축 라벨링 2014-12 -> 14-12 -> '14.12
				string gvHeaderText = gv.HeaderRow.Cells[i + first_month_idx].Text;
				string ls_base_dt = "'" + gvHeaderText.Substring(2, 5).Replace("-", ".");
				chart_line_type.AxisX.Labels[i] = ls_base_dt;

				//0이상일때만 보여준다.
				if (chart_line_type.Data[0, i] > 0)
				{
					chart_line_type.Points[0, i].PointLabels.Visible = true;
					li_cnt++;
				}
				else
				{
					chart_line_type.Points[0, i].PointLabels.Visible = false;
				}
			}

			if (li_cnt > 0)
			{
				ld_avg = ld_sum / li_cnt;
			}

			//CustomGridLine 초기화
			chart_line_type.AxisY.CustomGridLines.Clear();

			//CustomGridLine
			ChartFX.WebForms.CustomGridLine cgl1 = new ChartFX.WebForms.CustomGridLine();
			cgl1.Value = ld_avg;
			cgl1.Color = System.Drawing.Color.Red;
			cgl1.Width = 2;
			cgl1.Text = "Avg. : " + ld_avg.ToString("#,###,###");
			cgl1.Alignment = StringAlignment.Far;
			cgl1.LineAlignment = StringAlignment.Near;
			cgl1.TextColor = Color.Black;

			chart_line_type.AxisY.CustomGridLines.Add(cgl1);

			mpe_chart_type.Show();
		}
		#endregion

		#endregion

		#region CRUD (SearchProcess)

		//검색
		private void SearchProcess()
		{
			lbl_search_flag.Text = "SEARCH";
			SetSearchParameter();

			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			lo_dp.AddProperty("ls_base_from_ym", typeof(string), kw1);
			lo_dp.AddProperty("ls_base_to_ym", typeof(string), kw2);
			lo_dp.AddProperty("ls_training_part", typeof(string), kw3);
			lo_dp.AddProperty("ls_training_type_id", typeof(string), kw4);
			lo_dp.AddProperty("ls_search_type", typeof(string), kw5);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			using (Fit2010r_NT _Fit2010r_NT = new Fit2010r_NT())
			{
				lo_ds.Merge(_Fit2010r_NT.GetRegionalWeightTrainingAnalysisList(lo_dp));
			}

			SetChartTotalWeightCountByTrainingPart(lo_ds, "UPDMS_FIT_REPORT"); //운동부위별 총량
			SetChartMonthlyTotalWeightTrainingAnalysis(lo_ds, "UPDMS_FIT_REPORT"); //월별트레이닝결과

			gv_data_nodata.Visible = !DataSetUtil.CheckRowCount(lo_ds, "UPDMS_FIT_REPORT");

			gv_training_info.DataSource = lo_ds;
			gv_data.DataSource = lo_ds;
			gv_total.DataSource = lo_ds;

			gv_training_info.DataBind();
			gv_data.DataBind();
			gv_total.DataBind();

			string search_condition = "?sm=" + gs_sm + "&kw1=" + Server.UrlEncode(kw1) + "&kw2=" + Server.UrlEncode(kw2) + "&kw3=" + Server.UrlEncode(kw3) + "&kw4=" + Server.UrlEncode(kw4) + "&kw5=" + Server.UrlEncode(kw5);

			//즐겨찾기
			ibtn_favorite.Attributes.Add("onclick", "javascript:goFavoriteSearchPage('" + PID + "','" + search_condition + "');return false;");
		}

		#endregion

		#region Page_PreRender, ChangePageMode

		//Page_PreRender
		private void Page_PreRender(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				using (AccessCheck access = new AccessCheck())
				{
					//접근권한 체크
					if (!access.CheckPgmAccessGrant(PID, USER_ID, ACCESS_LOG_INFO))
					{
						Response.Redirect(URL_NO_AUTHORITY_REDIRECT_BASE);	//사용자의 권한은 요청하신 페이지를 볼 수 없습니다
					}
					//사용권한별 버튼처리
					PagePreRender.SetVisibleCtrl(this, access.CheckPgmUsingGrant(USER_DIV, PID), access.GetVisibleCtrl(PID));
				}
			}
			ChangePageMode();
		}

		//ChangePageMode
		private void ChangePageMode()
		{
			SetGridViewHeader(global.GetColumnListByPgmId(PID, LANG_SET));
		}

		#endregion

		#region GridView이벤트

		//운동부위, 운동명
		protected void gv_training_info_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			GridView gv = (GridView)sender;

			if (e.Row.RowType == DataControlRowType.Header)
			{
				e.Row.Cells[0].Font.Underline = true;
				e.Row.Cells[1].Font.Underline = true;
			}

			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				string trainingPartNm = e.Row.Cells[0].Text;
				string trainingNm = e.Row.Cells[1].Text;
				string trainingTypeId = gv.DataKeys[e.Row.RowIndex].Values["Training_Type_Id"].ToString();
				string trainingPart = gv.DataKeys[e.Row.RowIndex].Values["Training_Part"].ToString();

				string series = trainingPartNm + " - " + trainingNm;

				e.Row.Cells[0].Text = "<a href=\"javascript:void(0);\" onclick=\"viewChartPart('" + trainingPart + "');\">" + trainingPartNm + "</a>";
				e.Row.Cells[1].Text = "<a href=\"javascript:void(0);\" onclick=\"viewChartType('" + e.Row.RowIndex.ToString() + "', '" + series + "');\">" + trainingNm + "</a>";

				switch (trainingTypeId)
				{
					case "BA001": //소계
						e.Row.Attributes.Add("class", "sub_total_v1");
						break;
					case "BA002": //총계
						e.Row.Attributes.Add("class", "total_v3");
						for (int i = 0; i < e.Row.Cells.Count; i++)
						{
							e.Row.Cells[i].Attributes.Add("class", "div_line_tb_dbl");
						}
						//총계 colspan
						e.Row.Cells[0].ColumnSpan = 2;//화면에 보이는것. Visible=false는 안보이는것 포함
						e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Center;
						e.Row.Cells[0].Text = "<a href=\"javascript:void(0);\" onclick=\"viewChartType('" + e.Row.RowIndex.ToString() + "', '" + trainingPartNm + "');\">" + trainingPartNm + "</a>";
						e.Row.Cells[1].Visible = false;
						break;
					default:
						e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Center; //운동부위
						break;
				}
			}

			//머지
			SMGridView sGv = new SMGridView(this.Page, ref gv_training_info);
			sGv.RowSpanGridView(gv_training_info, 0); //운동부위
		}

		//RowDataBound
		protected void gv_data_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			GridView gv = (GridView)sender;

			string currYm = DateUtil.GetNow("yyyy-MM");

			e.Row.Cells[0].Visible = false;	//Training_Part 숨기기
			e.Row.Cells[1].Visible = false;	//Training_Part 숨기기
			e.Row.Cells[2].Visible = false;	//Training_Type_Id 숨기기
			e.Row.Cells[3].Visible = false;	//Training_Type_Id 숨기기
			e.Row.Cells[e.Row.Cells.Count - 1].Visible = false;	//Total 숨기기

			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				string trainingPart = gv.DataKeys[e.Row.RowIndex].Values["Training_Part"].ToString();
				string trainingTypeId = gv.DataKeys[e.Row.RowIndex].Values["Training_Type_Id"].ToString();

				switch (trainingTypeId)
				{
					case "BA001": //소계
						e.Row.Attributes.Add("class", "sub_total_v1");
						break;
					case "BA002": //총계
						e.Row.Attributes.Add("class", "total_v3");
						for (int i = 0; i < e.Row.Cells.Count; i++)
						{
							e.Row.Cells[i].Attributes.Add("class", "div_line_tb_dbl");
						}
						break;
					default:
						for (int i = 4; i < e.Row.Cells.Count - 1; i++)
						{
							string gvHeaderText = gv_data.HeaderRow.Cells[i].Text;

							//현재년월 하이라이트
							if (currYm == gvHeaderText)
							{
								e.Row.Cells[i].CssClass = "bg_peach";
							}
						}
						break;
				}

				for (int i = 4; i < e.Row.Cells.Count - 1; i++)
				{
					string baseYm = gv.HeaderRow.Cells[i].Text;

					e.Row.Cells[i].Text = String.Format("{0:#,###,##0}", Convert.ToDecimal(e.Row.Cells[i].Text));
					e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Right;

					//소계는 trainingTypeId를 빈값으로 넘긴다.
					if (trainingTypeId == "BA001")
					{
						trainingTypeId = "";
					}

					//총계는 trainingPart와 trainingTypeId를 빈값으로 넘긴다.
					if (trainingTypeId == "BA002")
					{
						trainingPart = "";
						trainingTypeId = "";
					}

					string data = e.Row.Cells[i].Text;
					string link = (data == "0") ? "javascript:void(0);" : "javascript:goMonthlyWeightTrainingResultPage('" + baseYm + "','" + trainingPart + "','" + trainingTypeId + "');";

					string finalData = "<span onclick=\"" + link + "\">" + data + "</span>";
					e.Row.Cells[i].Text = finalData;
				}
			}
		}

		//Total
		protected void gv_total_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			GridView gv = (GridView)sender;

			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				string trainingTypeId = gv.DataKeys[e.Row.RowIndex].Values["Training_Type_Id"].ToString();
				switch (trainingTypeId)
				{
					case "BA001": //소계
						e.Row.Attributes.Add("class", "sub_total_v1");
						break;
					case "BA002": //총계
						e.Row.Attributes.Add("class", "total_v3");
						for (int i = 0; i < e.Row.Cells.Count; i++)
						{
							e.Row.Cells[i].Attributes.Add("class", "div_line_tb_dbl");
						}
						break;
					default:
						break;
				}

				for (int i = 0; i < e.Row.Cells.Count; i++)
				{
					e.Row.Cells[i].Text = String.Format("{0:#,###,##0}", Convert.ToDecimal(e.Row.Cells[i].Text));
					e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Right;
				}
			}
		}

		#endregion

		#region 버튼이벤트

		//6개월
		protected void sbtn_6_m_Click(object sender, EventArgs e)
		{
			SetYearMonth(-5);
			SearchProcess();
		}

		//12개월
		protected void sbtn_12_m_Click(object sender, EventArgs e)
		{
			SetYearMonth(-11);
			SearchProcess();
		}

		//전체
		protected void sbtn_all_m_Click(object sender, EventArgs e)
		{
			ddl_search_from_year.SelectedIndex = 0;
			ddl_search_from_month.SelectedIndex = 0;
			ddl_search_to_year.SelectedIndex = ddl_search_to_year.Items.Count - 1;
			ddl_search_to_month.SelectedIndex = ddl_search_to_month.Items.Count - 1;

			SearchProcess();
		}

		//전년
		protected void ibtn_prev_year_Click(object sender, EventArgs e)
		{
			SetPrevNextYear(-1);
			SearchProcess();
		}

		//당년
		protected void ibtn_this_year_Click(object sender, EventArgs e)
		{
			SetThisYear();
			SearchProcess();
		}

		//차년
		protected void ibtn_next_year_Click(object sender, EventArgs e)
		{
			SetPrevNextYear(1);
			SearchProcess();
		}

		//검색
		protected void ibtn_search_Click(object sender, EventArgs e)
		{
			SetEnabledYearBtn();
			SearchProcess();
		}

		//엑셀
		protected void ibtn_excel_Click(object sender, EventArgs e)
		{
			lbl_search_flag.Text = "SEARCH";
			SetSearchParameter();

			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();

			//검색
			lo_dp.AddProperty("ls_base_from_ym", typeof(string), kw1);
			lo_dp.AddProperty("ls_base_to_ym", typeof(string), kw2);
			lo_dp.AddProperty("ls_training_part", typeof(string), kw3);
			lo_dp.AddProperty("ls_training_type_id", typeof(string), kw4);
			lo_dp.AddProperty("ls_search_type", typeof(string), kw5);
			lo_dp.AddProperty("ls_lang_set", typeof(string), LANG_SET);

			using (Fit2010r_NT _Fit2010r_NT = new Fit2010r_NT())
			{
				lo_ds.Merge(_Fit2010r_NT.GetRegionalWeightTrainingAnalysisList(lo_dp));
			}

			//2014-01,2014-02... -> 2014-01^2014-01:2013-04^2014-02
			//컬럼수만큼의 크기를 갖는 배열을 생성
			string[] columns = DateUtil.GetDiffMonthList(kw1, kw2).Split(',');
			string[] headerTexts = new string[columns.Length + 3]; // +3(Training_Part_Nm, Training_Nm, ..., Total)

			headerTexts[0] = "Training_Part_Nm^" + global.GetLabelNmBySeq(338, LANG_SET);//운동부위
			headerTexts[1] = "Training_Nm^" + global.GetLabelNmBySeq(336, LANG_SET);//운동명

			for (int i = 2; i < headerTexts.Length - 1; i++)
			{
				headerTexts[i] = columns[i - 2] + "^" + columns[i - 2];
			}

			headerTexts[headerTexts.Length - 1] = "Total^Total";

			string fileName = PID + "(" + global.GetMenuTitle(PID, LANG_SET) + ")";
			ExcelUtil.CreateExcelFileX(this.Page, fileName, lo_ds, headerTexts);
		}

		//운동부위별챠트
		protected void lbtn_set_chart_part_Click(object sender, EventArgs e)
		{
			bool isByWeight = (rbl_search_type.SelectedIndex == 0);
			int li_first_month_idx = 4;	//데이터시작(1월)의 index값

			SetChartTrainingPart(gv_data, li_first_month_idx, h_training_part.Value, isByWeight);
		}

		//운동별챠트
		protected void lbtn_set_chart_type_Click(object sender, EventArgs e)
		{
			bool isByWeight = (rbl_search_type.SelectedIndex == 0);
			int li_first_month_idx = 4;	//데이터시작(1월)의 index값

			SetChartTrainingType(gv_data, li_first_month_idx, Convert.ToInt32(h_row_idx.Value), isByWeight);
		}


		#endregion
	}
}